<template>
  <i v-if="isElIcon" class="el-icon" :title="tip" :style="{ fontSize: size + 'px', color }">
    <component :is="name" />
  </i>
  <svg v-else :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script lang="ts" setup>
const props = defineProps({
  // svg 图标组件名字
  name: {
    type: String,
    default: ''
  },
  // svg 大小
  size: {
    type: Number,
    default: 16
  },
  // svg 颜色
  color: {
    type: String,
    default: ''
  },
  // 是否是element的icon
  isElIcon: {
    type: Boolean,
    default: false
  },
  tip: {
    type: String,
    default: ''
  },
  // svg图的
  iconClass: {
    type: String,
    default: ''
  },
  className: {
    type: String,
    default: ''
  }
})

const iconName = computed(() => {
  return `#icon-${props.iconClass}`
})
const svgClass = computed(() => {
  if (props.className) {
    return 'svg-icon ' + props.className
  } else {
    return 'svg-icon'
  }
})
</script>
<style scoped lang="scss">
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
